package com.maxdu.labs.stt.activities;

import com.example.stt.R;
import com.maxdu.labs.stt.TabPagerAdapter;
import com.maxdu.labs.stt.fragments.FeedFragment;
import com.maxdu.labs.stt.fragments.TrainingsFragment;
import com.maxdu.labs.stt.fragments.TPlansFragment;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
public class MainTestMenuActivity extends FragmentActivity {
  ViewPager tab;
    TabPagerAdapter TabAdapter;
  ActionBar actionBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_test_menu);
        TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
        tab = (ViewPager)findViewById(R.id.pager);
        tab.setOnPageChangeListener(
                new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                      actionBar = getActionBar();
                      actionBar.setSelectedNavigationItem(position);
                     }
                });
        tab.setAdapter(TabAdapter);
        actionBar = getActionBar();
        //Enable Tabs on Action Bar
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        ActionBar.TabListener tabListener = new ActionBar.TabListener(){
		      @Override
		      public void onTabReselected(android.app.ActionBar.Tab tab,
		          FragmentTransaction ft) {
		    	  System.out.println("TAB (re)SELECTED === " + tab.getPosition());
		      }
		      @Override
		       public void onTabSelected(ActionBar.Tab _tab, FragmentTransaction ft) {
		              tab.setCurrentItem(_tab.getPosition());
		              System.out.println("TAB SELECTED === " + _tab.getPosition());
		          }
		      @Override
		      public void onTabUnselected(android.app.ActionBar.Tab tab,
		          FragmentTransaction ft) {
		        // TODO Auto-generated method stub
		    }};
      //Add New Tab
      /*
		    actionBar.addTab(actionBar.newTab().setText(getString(R.string.feed)).setTabListener(tabListener));
      actionBar.addTab(actionBar.newTab().setText(getString(R.string.tplans)).setTabListener(tabListener));
      actionBar.addTab(actionBar.newTab().setText(getString(R.string.my_trainings)).setTabListener(tabListener));
      //actionBar.addTab(actionBar.newTab().setText(getString(R.string.feed)).setTabListener(tabListener));
      Tab tab = actionBar.newTab();
      tab.setCustomView(R.layout.tab_feed);
      actionBar.addTab(tab.setTabListener(tabListener));
      */
      //tab FEED
	  createTab(R.layout.tab_landing,tabListener);
      createTab(R.layout.tab_feed,tabListener);
      createTab(R.layout.tab_tplans,tabListener);
      createTab(R.layout.tab_trainings,tabListener);
      createTab(R.layout.tab_friends,tabListener);
    }
    
    public void createTab(int view,ActionBar.TabListener tabListener) {
        Tab tab = actionBar.newTab();
        tab.setCustomView(view);
        actionBar.addTab(tab.setTabListener(tabListener));
    }
}